package logic;

import java.util.Calendar;

import logger.Logger;

public class DateTime {
	
	private static final String INVALID_DATE_INPUT = "Invalid date input";
	private static final String DATESTRING_TOMORROW = "tomorrow";
	private static final String DATESTRING_TODAY = "today";
	private static final String DATESTRING_YESTERDAY = "yesterday";
	private static final String DATESTRING_SUNDAY = "sunday";
	private static final String DATESTRING_SUN = "sun";
	private static final String DATESTRING_SATURDAY = "saturday";
	private static final String DATESTRING_SAT = "sat";
	private static final String DATESTRING_FRIDAY = "friday";
	private static final String DATESTRING_FRI = "fri";
	private static final String DATESTRING_THURSDAY = "thursday";
	private static final String DATESTRING_THURS = "thurs";
	private static final String DATESTRING_WEDNEDAY = "wednesday";
	private static final String DATESTRING_WED = "wed";
	private static final String DATESTRING_TUESDAY = "tuesday";
	private static final String DATESTRING_TUES = "tues";
	private static final String DATESTRING_MONDAY = "monday";
	private static final String DATESTRING_MON = "mon";
	
	private static final int TOMORROW = 12;
	private static final int TODAY = 11;
	private static final int YESTERDAY = 10;
	
	private static final int SUNDAY = 6;
	private static final int SATURDAY = 5;
	private static final int FRIDAY = 4;
	private static final int THURSDAY = 3;
	private static final int WEDNESDAY = 2;
	private static final int TUESDAY = 1;
	private static final int MONDAY = 0;
	private static final int INVALID = -1;
	
	public int indexOfCommand;
	public int commandType;
	public int indexOfDate;
	public int dayType;
	public int indexOfTime;
	public int typeOfTime;
	
	//@author A0085082E
	public static Calendar nextWeek(Calendar current){
		
		current.add(Calendar.DATE, 7);
		return current;
	}
	
	public static Calendar tomorrow(Calendar current){
		current.add(Calendar.DATE, 1);
		
		return current;
	}
	
	public static Calendar addNumberOfDays(Calendar current, int num){
		current.add(Calendar.DATE, num);
		
		return current;
	}
	
	public static double getTimeInMilis(Calendar current){
		return current.getTimeInMillis();
	}
	
	public static double getTimeDifference(Calendar first, Calendar second){
		return first.getTimeInMillis() - second.getTimeInMillis();
	}
	
	public static void setTimeAsMidnight(Calendar current){
		current.set(Calendar.HOUR, 0);
		current.set(Calendar.MINUTE, 0);
		current.set(Calendar.SECOND, 0);
	}
	
	public static void setTimeAsMinuteBeforeMidnight(Calendar current){
		current.set(Calendar.HOUR_OF_DAY, 23);
		current.set(Calendar.MINUTE, 59);
		current.set(Calendar.SECOND, 59);
	}
	
	
	/*
	 * Function takes in a string, then return a value representing the day.
	 */
	public static int isDayOfWeek(String day){
		
		switch(day.toLowerCase()){
		case DATESTRING_MON: case DATESTRING_MONDAY:
			return MONDAY;
		case DATESTRING_TUES: case DATESTRING_TUESDAY:
			return TUESDAY;
		case DATESTRING_WED: case DATESTRING_WEDNEDAY:
			return WEDNESDAY;
		case DATESTRING_THURS: case DATESTRING_THURSDAY:
			return THURSDAY;
		case DATESTRING_FRI: case DATESTRING_FRIDAY:
			return FRIDAY;
		case DATESTRING_SAT: case DATESTRING_SATURDAY:
			return SATURDAY;
		case DATESTRING_SUN: case DATESTRING_SUNDAY:
			return SUNDAY;
		case DATESTRING_YESTERDAY:
			return YESTERDAY;
		case DATESTRING_TODAY:
			return TODAY;
		case DATESTRING_TOMORROW:
			return TOMORROW;
			
			default:
				Logger.add(INVALID_DATE_INPUT);
				return INVALID;
				
			
		}
	}
	
	public static int getDayOfTheWeek(Calendar day){
		
		switch(day.get(Calendar.DAY_OF_WEEK)){
		case Calendar.MONDAY:
			return MONDAY;
		case Calendar.TUESDAY:
			return TUESDAY;
		case Calendar.WEDNESDAY:
			return WEDNESDAY;
		case Calendar.THURSDAY:
			return THURSDAY;
		case Calendar.FRIDAY:
			return FRIDAY;
		case Calendar.SATURDAY:
			return SATURDAY;
		case Calendar.SUNDAY:
			return SUNDAY;
			default:
				Logger.add(INVALID_DATE_INPUT);
				return INVALID;
			
		}
	}
	
	public static boolean isNonNumericDateNotWeekDay(String date){
		return isDayOfWeek(date)>= YESTERDAY && isDayOfWeek(date) <= TOMORROW;
	}
	
	public static boolean isNonNumericDateWeekDay(String date){
		return isDayOfWeek(date)>= MONDAY && isDayOfWeek(date) <= SUNDAY;
	}
}
